package com.zb.controller;


import com.zb.entity.dto.OrderTableFieldDto;
import com.zb.result.Result;
import com.zb.search.SearchDto;
import com.zb.service.ZjAdmFactoryOrderTableFieldService;
import com.zb.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 后台厂商工单列表表头字段表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2024-04-10
 */
@Api(tags = "品牌厂商工单表头字段类接口")
@RestController
@RequestMapping("/factory/order/table/field")
public class ZjAdmFactoryOrderTableFieldController {
    @Resource
    private ZjAdmFactoryOrderTableFieldService admFactoryOrderTableFieldService;

    @ApiOperation("保存或修改工单表头字段")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid OrderTableFieldDto fieldDto) {
        admFactoryOrderTableFieldService.save(fieldDto);
        return Result.success(null == fieldDto.getId()? "新增表头字段成功" : "修改表头字段成功");
    }
    @ApiOperation("获取表头字段列表")
    @PostMapping("/getList")
    public Result getList(@RequestBody SearchDto search) {
        return Result.success("获取表头字段列表成功").data(admFactoryOrderTableFieldService.getList(search));
    }

    @ApiOperation("根据表头ID获取详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "表头字段ID", required = true) Long id) {
        return Result.success("获取详情成功").data(PageUtil.row(admFactoryOrderTableFieldService.getDetail(id)));
    }

    @ApiOperation("批量修改列隐藏或显示")
    @PostMapping("/updateShowColumn")
    public Result updateShowColumn(@RequestParam @ApiParam(value = "是否显示列：false-隐藏，true-显示", required = true, example = "true") boolean showColumn,
                                   @RequestBody @ApiParam(value = "表头字段ID", required = true) List<Long> ids) {
        admFactoryOrderTableFieldService.updateShowCloumBatchById(showColumn, ids);
        return Result.success(showColumn? "显示列更新成功" : "隐藏列更新成功");
    }

    @ApiOperation("批量修改列冻结或解冻")
    @PostMapping("/updateFreezeColumn")
    public Result updateFreezeColumn(@RequestParam @ApiParam(value = "是否冻结列：false-解冻，true-冻结", required = true, example = "false") boolean freezeColumn,
                                     @RequestBody @ApiParam(value = "表头字段ID", required = true) List<Long> ids) {
        admFactoryOrderTableFieldService.updateFreezeCloumBatchById(freezeColumn, ids);
        return Result.success(freezeColumn? "冻结列更新成功" : "解冻列更新成功");
    }

    @ApiOperation("批量启用或禁用表头字段")
    @PostMapping("/disabled")
    public Result disabled(@RequestParam @ApiParam(value = "表头字段状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                           @RequestBody @ApiParam(value = "表头字段ID", required = true) List<Long> ids) {
        admFactoryOrderTableFieldService.updateDisabledBatchById(status, ids);
        return Result.success(status? "禁用表头字段成功" : "启用表头字段成功");
    }

}
